﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using MaciejGrabek.WP7.Services.Phone.Entities;
using Microsoft.Phone.Controls;
using MaciejGrabek.WP7.Services.Phone.Tools;

namespace MaciejGrabek.WP7.Services.Phone.Demo
{
    public partial class MainPage : PhoneApplicationPage
    {
        GameServicesCaller caller = new GameServicesCaller("http://localhost:2442", "catcheggs", "E47552CF-AF1F-4cb6-BA2E-3F7289F98233");

        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void btnAddGameResult_Click(object sender, RoutedEventArgs e)
        {   
            caller.SaveGameResult(new GameResultDto()
                                      {
                                          DeviceId = IdsProvider.GetDeviceId(),
                                          Score = 123,
                                          PlayerName = "Maciej Grabek"
                                      }, delegate {
                                                      this.Dispatcher.BeginInvoke(() => { MessageBox.Show("Done"); });
                                      });

        }

        private void btnGetResults_Click(object sender, RoutedEventArgs e)
        {
            caller.GetGameResults((IEnumerable<GameResultLightDto> items) =>
                                      {
                                          this.Dispatcher.BeginInvoke(() => { MessageBox.Show(items.Count().ToString()); });
                                      }, 
                                      delegate(Exception exception) { });
        }
    }
}